Step 1: Node

Create a new folder and call it hello-node.

Add a new file, server.js, to this folder with the following content:

console.log("Hello Node!");

Open the terminal. Change the directory to hello-node and then run the server.js file with the following command:

node server.js

This should print to the console “Hello Node!”

So, what did happen?!

Node executed our JavaScript code outside of a browser. This is plenty interesting in itself!! Before Node, we could only use JavaScript to build applications that run inside of a browser. Every browser has a JavaScript Engine that takes your JavaScript code and turns it into an executable form. Node uses Google's JavaScript engine (called V8) to convert JavaScript into bytecodes but runs it outside of a browser.

A JavaScript engine, at its core, consists of an interpreter and a runtime environment. In the browser, the runtime environment provides global objects such as window or document that enable JavaScript to interface with the browser and the webpage it is part of. These objects are not available in Node, however. Try to print window or document and see what happens!

console.log("Hello Node!");
console.log(window);
console.log(document);

Instead, Node provides other modules not available in browsers, such as objects for working with the file system, network, operating system, etc. That is how we can use Node to write server-side code with JavaScript. Try the following code snippet, for instance.

const fs = require("fs");     // import File System module
const http = require("http"); // import HTTP Networking module

console.log("Hello Node!");
// console.log(window);    // not available in Node
// console.log(document);  // not available in Node
console.log(fs);
console.log(http);

Aside: Node is not the only option out there! There are Deno and Bun, although, these are not nearly as popular as Node.